import requests
import csv

# f = open('全球疫情数据.csv', mode='a', encoding='utf-8', newline='')
# csv_writer = csv.DictWriter(f, fieldnames=[
#     '国家名称','确诊人数','新增确诊人数','治愈人数','死亡人数','现有确诊人数'
# ])
# csv_writer.writeheader()    # 写入头


f = open('全球疫情数据.csv', mode='a', encoding='utf-8', newline='')
csv_writer = csv.writer(f)

url = 'https://api.inews.qq.com/newsqa/v1/query/inner/publish/modules/list?modules=localCityNCOVDataList,diseaseh5Shelf'

json_data = requests.post(url).json()

chinaTotal = json_data['data']['diseaseh5Shelf']['chinaTotal']

confirm = chinaTotal['confirm']
confirmAdd = chinaTotal['confirmAdd']
dead = chinaTotal['dead']
heal = chinaTotal['heal']
localConfirmH5 = chinaTotal['localConfirmH5']
name = '中国'
# dic = {
#     '国家名称': '中国',  # 国家名称
#     '确诊人数': chinaTotal['confirm'],  # 确诊人数
#     '新增确诊人数': chinaTotal['confirmAdd'],  # 新增确诊人数
#     '治愈人数': chinaTotal['heal'],  # 治愈人数
#     '死亡人数': chinaTotal['dead'],  # 死亡人数
#     '现有确诊人数': chinaTotal['nowConfirm']  # 现有确诊人数
# }
csv_writer.writerow([name, confirm, confirmAdd,heal, dead, localConfirmH5])
f.close()

# print(name,confirm,confirmAdd,dead,heal,nowConfirm)